#define _CRT_SECURE_NO_WARNINGS 1

#pragma once
#include<iostream>
#include<string>
#include<string.h>

using namespace std;

namespace zhao
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;

		iterator begin()
		{
			return _str;
		}
		const_iterator begin() const
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}
		const_iterator end() const
		{
			return _str + _size;
		}

		string& operator= (const string& str)
		{
			if (this!=&str)
			{
				delete[] _str;
				_str = new char[str._capacity + 1];
				strcpy(_str,str._str);
				_size = str._size;
				_capacity = str._capacity;

			}
			return *this;
		}
		size_t size() const
		{
			return _size;
		}

		size_t capacity() const
		{
			return _capacity;
		}
		void clear()
		{
			delete[] _str;
			_str = nullptr;
			_size = _capacity;
		}

		string& operator+= (const char* s);
		void insert(size_t pos, const char* s);
		char& operator[] (size_t pos)
		{
			return _str[pos];
		}
		const char& operator[] (size_t pos) const
		{
			return _str[pos];
		}
///////////////////////////////////////////////////////////////////////////
		void reserve(size_t n=0);
		void push_back(char c);
		string& append(const char* s);






		string(const char *str)
		{
			_size = strlen(str);
			_capacity = _size;
			_str = new char[_capacity + 1];
			strcpy(_str, str);
		}

		string(const string& s)
		{
			_size = s._size;
			_capacity = s._capacity;
			delete[] _str;
			_str = new char[_capacity + 1];
			strcpy(_str, s._str);
		}


		~string()
		{
			delete[] _str;
			_str = nullptr;
			_size = _capacity = 0;
		}
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
 

}

